﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using ArbolandiaBL;

public partial class _ServicioCliente : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            string category = Request.QueryString["cat"] != null ? Request.QueryString["cat"] : "";
            int cat = 0; Int32.TryParse(category, out cat);
            InitPage();
            LoadContent(cat);
        }

    }
    protected void LoadContent(int category)
    {
        //Llenamos ruta
        lblRoute.Text = "INICIO / " + "Servicio Cliente";
        //llenamos el lado izquierdo
        var contentList = new Service().GetContents(0);
        if (category == 0 && contentList != null && contentList.Count() > 0)
        {
            category = contentList.Min(w => w.Id);
        }
        foreach (var t in contentList)
        {
            //left banner
            var div = new HtmlGenericControl("div");
            var hl = new HyperLink();
            hl.ID = t.Category.ToString();
            hl.Text = "-" + t.Category;
            hl.NavigateUrl = "~/ServicioCliente.aspx?c=7&cat=" + t.Id.ToString();
            if (category == t.Id) { hl.Style.Add("color", "#a8c32d"); }
            div.Controls.Add(hl);
            contentCategory.Controls.Add(div);
        }
        //Llenamos Contenido.
        var content = new Service().GetContent(category);
        if (content != null)
        {
            sectionTop.ImageUrl = content.UrlImage;
            contenttext.InnerHtml = content.Content;
        }

    }
    protected void InitPage()
    {
        LoadBanners();
    }

    protected void LoadBanners()
    {
        var banner1 = new ServiceUI().GetBanner(BannerType.Top);
        for (int i = 0; i < banner1.Count(); i++)
        {
            var c = new HyperLink() { ImageUrl = banner1[i].Url, NavigateUrl = banner1[i].LinkUrl };
            var p = new HyperLink() { NavigateUrl = banner1[i].LinkUrl, Text = ((i + 1)).ToString() };
            c.Target = "_blank";
            p.Attributes.Add("rel", ((i + 1)).ToString());
            imagereel.Controls.Add(c);
            paging.Controls.Add(p);
        }
        var banner2 = new ServiceUI().GetBanner(BannerType.Middle);
        for (int i = 0; i < banner2.Count(); i++)
        {
            var c = new HyperLink() { ImageUrl = banner2[i].Url, NavigateUrl = banner2[i].LinkUrl };
            var p = new HyperLink() { NavigateUrl = banner2[i].LinkUrl, Text = ((i + 1)).ToString() };
            c.Target = "_blank";
            p.Attributes.Add("rel", ((i + 1)).ToString());
            imagereel2.Controls.Add(c);
            paging2.Controls.Add(p);
        }
        var banner3 = new ServiceUI().GetBanner(BannerType.Bottom);
        for (int i = 0; i < banner3.Count(); i++)
        {
            var c = new HyperLink() { ImageUrl = banner3[i].Url, NavigateUrl = banner3[i].LinkUrl };
            var p = new HyperLink() { NavigateUrl = banner3[i].LinkUrl, Text = ((i + 1)).ToString() };
            c.Target = "_blank";
            p.Attributes.Add("rel", ((i + 1)).ToString());
            imagereel3.Controls.Add(c);
            paging3.Controls.Add(p);
        }
    }


}